package org.zht.dormpro.pub;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResponseMap extends HashMap<String,Object> {
    public ResponseMap(){
        put("status",1000);
        put("desc","操作成功");
    }
    public static ResponseMap error(String desc){
        ResponseMap responseMap = new ResponseMap();
        responseMap.put("status",1001);
        responseMap.put("desc",desc);
        return responseMap;
    }
    public static ResponseMap error(String code,String desc){
        ResponseMap responseMap = new ResponseMap();
        responseMap.put("status",code);
        responseMap.put("desc",desc);
        return responseMap;
    }
    public static ResponseMap success(String desc){
        ResponseMap responseMap = new ResponseMap();
        responseMap.put("desc",desc);
        return responseMap;
    }

    /**
     * 返回map
     * @param map
     * @return
     */
    public static ResponseMap success(Map<String,Object> map){
        ResponseMap responseMap = new ResponseMap();
        responseMap.put("list",map);
        responseMap.put("desc","操作成功");
        return responseMap;
    }

    /**
     * 返回javabean
     * @param o
     * @return
     */
    public static ResponseMap success(Object o){
        ResponseMap responseMap = new ResponseMap();
        responseMap.put("model",o);
        responseMap.put("desc","操作成功");
        return responseMap;
    }
    /**
     * 返回表格数据
     * @return
     */
    public static ResponseMap success(List rows,Map attr){
        ResponseMap responseMap = new ResponseMap();
        responseMap.put("rows",rows);
        responseMap.putAll(attr);
        responseMap.put("desc","操作成功");
        return responseMap;
    }
}
